from django.conf import settings
from django.core.mail import send_mail
from celery_tasks.main import app
import logging
logger = logging.getLogger('django')
@app.task(name='send_email')
def send_email(to_email, meiduo_cleck_key):

    # 主题
    subject = '欢迎登录美多商城'

    # 内容
    html_message = '<p>尊敬的用户您好</p>'\
                   '<p>欢迎登录美多商城</p>'\
                    '<p>您的邮箱是:%s,请点击下面链接完成认证</p>'\
                    '<a href="%s">%s</a>' % (to_email, meiduo_cleck_key, meiduo_cleck_key)
    # 发送目标list
    email_list = [to_email]

    # 发件人信息
    from_user_info = settings.EMAIL_FROM



    # 发送邮件
    try:
        send_mail(subject, "", from_user_info, email_list, html_message=html_message)

    except Exception as e:
        logger.error(e)

